from appium import webdriver
from time import sleep
from method.excelAnddir import *

desired_caps = {
    "platformName": "Android",
    "automationName": "uiautomator2",
    "platformVersion": "9",
    "deviceName": '2023110100001087',
    "appPackage": "com.seven.qaml.burstserven",
    "appActivity": "com.seven.qaml.burstserven.MainActivity",
    'skipServerInstallation': False,
    'skipDeviceInitialization': False,
    "noReset": True
}
appium_server_url = 'http://127.0.0.1:4723'
drive = webdriver.Remote(appium_server_url, desired_caps)

while True:
    if drive.find_elements('id', 'com.seven.qaml.burstserven:id/text_ver') != []:
        drive.keyevent(66)
        break
drive.keyevent(132)
sleep(2)
drive.find_element("id", "com.seven.qaml.burstserven:id/switch_qs_state").click()
sleep(2)
drive.keyevent(4)

sleep(1)
cis = 1
while cis < 100:
    drive.keyevent(12)  # 点击5
    sleep(1)
    # print('准备完成，按‘确定’键开始扫描'
    drive.keyevent(66)
    # 对码
    sleep(15)
    drive.keyevent(66)
    # 验证
    sleep(10)
    drive.keyevent(66)
    # 充电
    sleep(1)
    drive.keyevent(300)
    sleep(26)

    cs = 0
    while cs < 6:
        print('起爆未成功，正在重新起爆')
        os.system(f"python action/qibao.py")
        sleep(2)
        cs += 1

    if drive.find_elements('id', 'com.seven.qaml.burstserven:id/btn_otherParam') != []:
        drive.back()
    # sleep(10)
    if drive.find_elements("id", "android:id/button2") != []:
        drive.find_element("id", "android:id/button2").click()  # 取消可用更新


    print(f'=====>\033[7;32m起爆第{cis}次已完成！\033  \n')
    cis += 1
